package com.qishenyuan.competition.exception;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

/**
 * @author qishenyuan
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class BusinessException extends RuntimeException{

    private final int errorCode;

    private final String errorMessage;

    public BusinessException(BusinessErrorType businessErrorType) {
        this.errorCode = businessErrorType.getCode();
        this.errorMessage = businessErrorType.getMessage();
    }

    public BusinessException(int errorCode, String errorMessage) {
        super(Integer.valueOf(errorCode).toString());
        this.errorCode = errorCode;
        this.errorMessage = StringUtils.isNotBlank(errorMessage) ? errorMessage : this.getClass().getSimpleName();
    }

}
